package org.aplombh.java.interview.newcoder;

import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class HJ8_合并表记录 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int n = in.nextInt();
            TreeMap<Integer, Integer> res = new TreeMap<>();
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                int y = in.nextInt();
                if (res.containsKey(x)) {
                    res.put(x, res.get(x) + y);
                } else {
                    res.put(x, y);
                }
            }
            for (Map.Entry<Integer, Integer> t : res.entrySet()) {
                System.out.println(t.getKey() + " " + t.getValue());
            }
        }
    }
}
